﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Fallow : MonoBehaviour
{
    public Transform player;
    public float factor;
    [Header("限定区域参数")]
    public Vector2 minPos, maxPos;


    private void LateUpdate()
    {
        if (player != null)
        {
            if (transform.position != player.position)
            {
                Vector3 midPos = player.position;
                midPos.x = Mathf.Clamp(player.position.x, minPos.x, maxPos.x);//区域限定
                midPos.y = Mathf.Clamp(player.position.y, minPos.y, maxPos.y);
                transform.position = Vector3.Lerp(transform.position, midPos, factor);
            }
        }
        else
        {
            GameObject playerObj = GameObject.FindGameObjectWithTag("Player");
            player = playerObj.transform;
        }
    }
}
